#include <iostream>
#include <cstring>
using namespace std;

class Point
{
public:
    /*友元函数*/
    friend std::ostream& operator<<(std::ostream &os, const Point & p);
    Point(int x, int y):m_x(x), m_y(y){}
    Point operator+(const Point &p);

private:
    int m_x;
    int m_y;

};

template<typename Item>
class Array
{
public:
    template<typename T> friend std::ostream& operator<< (std::ostream &os, const Array<T> & array);
private:
    Item * m_data;
    int m_size;
    int m_capacity;
    /**/
    const int default_value = 10;
public:
    Array() : Array(10){}
    Array(int capacity)
    {
        if (capacity <= 0)
        {
            capacity = default_value;
        }
    

    m_data = new Item[capacity];
    if (m_data == nullptr)
    {
        throw "new error";
    }
    /*清空*/
    memset(m_data, 0, sizeof(Item) * capacity);
    m_size = 0;
    m_capacity = capacity;
    }
    /*析构函数*/
    ~Array()
    {
        if (m_data)
        {
            delete[]m_data;
        }

    }
private:
    bool checkIndexLegal(int index);

public:
    int add(Item value);
    void insert(int index, Item value);
    Item get(int index);
    void remove(int index);
    int size();
    Item operator[](int index);
};


int main()
{
    Array<int>array1;

    array1.add(11);
    array1.add(22);
    array1.add(33);

    cout<<array1<<endl;
    return 0;
}

template <typename Item>
bool Array<Item>::checkIndexLegal(int index)
{
    if (index < 0 || index >= this->m_size)
    {
        return false;
    }
    
    return true;
}

Point Point::operator+(const Point &p)
{
    Point result(0, 0);
    result.m_x = this->m_x + p.m_x;
    result.m_y = this->m_x + p.m_y;
    return result;
}

std::ostream& operator<<(std::ostream &os, const Point & p)
{
    os<<"x:"<<p.m_x<<" ,y:"<<p.m_y;
    return os;
}


/*类模板类外实现需要加上模板信息*/
template<typename Item>
int Array<Item>::add(Item value)
{
    if (m_size == m_capacity)
    {
        /*扩容*/
    }
    /*程序到这里 空间够*/
    m_data[m_size++] = value;
    return 0;
}

// template<typename Item>
// Item Array<Item>:: get(int index)
// {
//     if (checkIndexLegal(index))
//     {
//         return xxx;
//     }
    
//     return this->m_data[index];
// }

template<typename Item> ostream& operator<<(std::ostream &os, const Array<Item> & array)
{
    cout<<"[";
    for(int idx = 0; idx < array.m_size; idx++)
    {
        cout<<array.m_data[idx];
        if (idx != array.m_size - 1)
        {
            cout<<",";
        }
    }
    cout<<"]";
    return os;
}